package com.keya.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;

/**
 * 文件上传工具类.
 *
 * @author : xf.he
 * @version : 1.0 2023/8/7
 * @since : 1.0
 **/
public class MultipartFileUtils {

    public static void uploadFiles(MultipartFile[] files, Path uploadDir) throws IOException {
        File destFile = uploadDir.toFile();
        if (!destFile.exists()) {
            destFile.mkdirs();
        }
        for (MultipartFile file : files) {
            file.transferTo(new File(uploadDir + "/" + file.getOriginalFilename()));
        }
    }
}
